package com.mutual.vipAnnualFee.service.impl;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

import javax.annotation.Resource;

import org.joda.time.DateTime;
import org.springframework.stereotype.Service;

import com.mutual.vipAnnualFee.dao.VipAnnualFeeDao;
import com.mutual.vipAnnualFee.pojo.VipAnnualFee;
import com.mutual.vipAnnualFee.service.VipAnnualFeeService;

@Service
public class VipAnnualFeeServiceImpl implements VipAnnualFeeService {

	@Resource
	private VipAnnualFeeDao vipAnnualFeeDao;
	
	@Override
	public void insert(VipAnnualFee entity) {
		vipAnnualFeeDao.insertSelective(entity);
	}

	@Override
	public void updateByPrimaryKey(VipAnnualFee entity) {
		
	}

	@Override
	public VipAnnualFee selectByPrimaryKey(Serializable entityid) {
		return null;
	}

	@Override
	public VipAnnualFee selectVipAnnualFeeByIdCodeAndYear(VipAnnualFee vipAnnualFee) {
		return vipAnnualFeeDao.selectVipAnnualFeeByIdCodeAndYear(vipAnnualFee);
	}

	@Override
	public BigDecimal getVipAnnuaFee(VipAnnualFee vipAnnualFee) {
		VipAnnualFee vipAnnualFeeSelect = vipAnnualFeeDao.selectVipAnnualFeeByIdCodeAndYear(vipAnnualFee);
		BigDecimal annualFee = BigDecimal.valueOf(50);//默认需要交会费
		if(vipAnnualFeeSelect!=null) {
			Date createDate = vipAnnualFeeSelect.getCreateDate();
			DateTime dateTime = new DateTime(createDate);
			DateTime nextYear =  dateTime.plusYears(1);
			Date nowDate = new Date();
			if(nextYear.getMillis()>nowDate.getTime()) {
				annualFee=BigDecimal.ZERO;
			}
		}
		return annualFee;
	}

	@Override
	public int updatePaymentStatus(VipAnnualFee vipAnnualFee) {
		return vipAnnualFeeDao.updatePaymentStatus(vipAnnualFee);
	}
}
